/*
 * Copyright (c) 2024-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "iotc_wifi.h"
#include "iotc_errcode.h"
#include "iotc_mem.h"
#include "iotc_log.h"

int32_t IotcGetWifiInfo(uint8_t *ssidBuf, uint32_t *ssidBufLen, uint8_t *pwdBuf, uint32_t *pwdBufLen)
{
    return IOTC_OK;
}

int32_t IotcSetWifiInfo(const uint8_t *ssid, uint32_t ssidLen, const uint8_t *pwd, uint32_t pwdLen)
{
    return IOTC_OK;
}

int32_t IotcRestartWifi(void)
{

    return IOTC_OK;
}

int32_t IotcConnectWifiByBssid(int32_t type, const uint8_t *bssid, uint32_t bssidLen)
{
    return IOTC_OK;
}

int32_t IotcGetLastConnectResult(void)
{
    return IOTC_WIFI_CONNECT_OK;
}

int32_t IotcScanWifi(const IotcWifiScanParam *param)
{
    return IOTC_OK;
}

int32_t IotcGetWifiScanResult(IotcWifiList **scanList)
{
    return IOTC_OK;
}

int32_t IotcFreeWifiScanResult(IotcWifiList *scanList)
{
    return IOTC_OK;
}

int32_t IotcConnectWifi(void)
{
    return IOTC_OK;
}

int32_t IotcReconnectWifi(void)
{
    return IOTC_OK;
}

int32_t IotcGetWifiBssid(uint8_t *buf, uint32_t len)
{
    return IOTC_OK;
}

int32_t IotcGetWifiRssi(int8_t *rssi)
{
    return IOTC_OK;
}

int32_t IotcDeleteWifiInfo(void)
{
    return IOTC_OK;
}

int32_t IotcRegisterEventCallback(const IotcWifiEvent *cb)
{
    return IOTC_OK;
}

int32_t IotcDisconnectWifi(void)
{
    return IOTC_OK;
}

int32_t IotcStartSoftAp(const uint8_t *ssid, uint32_t ssidLen, const uint8_t *pwd, uint32_t pwdLen)
{
    IOTC_LOGI("IotcStartSoftAp, ssid:%s, ssidLen:%d", (const char*)ssid, ssidLen);

    return IOTC_OK;
}

int32_t IotcStopSoftAp(void)
{
    return IOTC_OK;
}

void IotcUnregEventCallback(void)
{
    return;
}

int32_t IotcGetSoftapStationInfo(IotcStationList **staList)
{
    if (staList == NULL || *staList != NULL) {
        IOTC_LOGW("param invalid");
        return IOTC_ERR_PARAM_INVALID;
    }

    size_t totalSize = sizeof(IotcStationList) + 1 * sizeof(IotcStationInfo);
    IotcStationList *sta = (IotcStationList *)IotcMalloc(totalSize);
    if (sta == NULL) {
        IOTC_LOGW("malloc error %u", totalSize);
        return IOTC_ADAPTER_MEM_ERR_MALLOC;
    }

    if (memset_s(sta, totalSize, 0, totalSize) != 0) {
        IotcFree(sta);
        return IOTC_ERROR;
    }

    sta->num = 1;
    sta->stationList[0].ip = 0x7f000001;

    uint8_t mac[] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
    if (memcpy_s(sta->stationList[0].mac, sizeof(sta->stationList[0].mac), mac, sizeof(mac)) != 0) {
        IotcFree(sta);
        return IOTC_ERROR;
    }

    *staList = sta;

    return IOTC_OK;
}

void IotcFreeSoftapStationInfo(IotcStationList *staList)
{
    return;
}

int32_t IotcSoftapDisassociateSta(uint8_t *mac, uint32_t len)
{
    return IOTC_OK;
}

int32_t IotcSoftapAddTxPower(int power)
{
    return IOTC_OK;
}

int32_t IotcGetWifiMode(void)
{
    return IOTC_OK;
}